package com.lemon.smartsafetynew.ui.adapter.monitor;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.monitor.MonitorCompanyVo;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/16.
 */

public class MonitorCompanyListAdapter extends LemonRcvAdapter<MonitorCompanyVo> {

    private RecyclerTClickListener<MonitorCompanyVo> mListener;

    public MonitorCompanyListAdapter(@Nullable List<MonitorCompanyVo> data,
                                     RecyclerTClickListener<MonitorCompanyVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new CompanyItem();
    }

    public class CompanyItem implements AdapterItem<MonitorCompanyVo> {

        @Bind(R.id.monitor_item_tv)
        TextView monitorItemTv;
        @Bind(R.id.company_name_tv)
        TextView companyNameTv;
        @Bind(R.id.company_safer_tv)
        TextView companySaferTv;
        @Bind(R.id.safer_tel_tv)
        TextView saferTelTv;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;

        private MonitorCompanyVo companyVo;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.item_electrical_company_recycler_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(companyVo, pos);
                }
            });
        }

        @Override
        public void handleData(MonitorCompanyVo monitorCompanyVo, int position) {
            companyVo = monitorCompanyVo;
            pos = position;

        }
    }
}
